//---------------------------------------------------------------------
//  This file is part of the Background Motion solution.
// 
//  Copyright (C) Mindscape (TM).  All rights reserved.
//  http://www.mindscape.co.nz
// 
//  THIS CODE AND INFORMATION ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY
//  KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
//  IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
//  PARTICULAR PURPOSE.
//---------------------------------------------------------------------

using System;
using System.Collections.Generic;

namespace Mindscape.BackgroundMotion.Core
{
  /// <summary>
  /// Represents a simple broker to be used with the ServiceLocator
  /// </summary>
  /// <remarks>
  /// This is a generic container which allows any type of object to be registered
  /// </remarks>
  public sealed class SimpleServiceBroker : IServiceBroker
  {
    private readonly Dictionary<Type, object> _services = new Dictionary<Type, object>();

    /// <summary>
    /// Gets a stored service from the broker
    /// </summary>
    /// <returns>The service which adheres to the generic type requested</returns>
    public T Get<T>()
    {
      return (T)_services[typeof(T)];
    }

    /// <summary>
    /// Registers a service with the broker
    /// </summary>
    /// <param name="service">The service.</param>
    public void RegisterService<T>(T service)
    {
      _services[typeof(T)] = service;
    }
  }
}